package com.stroke.util;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * This class used to create basic shapes
 * @author Igor Bubelov 
 * @date 3/7/11 7:54 PM
 * @version 1.0
 */
public class SampleImageFactory {
    /**
     * Returns a rectangle with specified size and color
     * @author Igor Bubelov
     * @param width
     * @param height
     * @param color
     * @return an <code>Image</code> object
     */
    public static Image createRectangle(int width, int height, Color color) {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g = image.createGraphics();

        g.setColor(color);

        g.setRenderingHints(RenderingHintsFactory.createBest());

        g.fillRect(0, 0, width, height);

        g.dispose();

        return image;
    }

     /**
     * Returns an oval with specified size and color
     * @author Ivan Melnikov
     * @param width
     * @param height
     * @param color
     * @return an <code>Image</code> object
     */
    public static Image createOval(int width, int height, Color color) {
        BufferedImage image = new BufferedImage(width, height , BufferedImage.TYPE_INT_ARGB);

        Graphics2D g = image.createGraphics();

        g.setColor(color);

        g.setRenderingHints(RenderingHintsFactory.createBest());

        g.fillOval(0, 0, width, height);

        g.dispose();

        return image;
    }

     /**
     * Returns a triangle with specified size and color
     * @author Ivan Melnikov
     * @param width
     * @param height
     * @param color
     * @return an <code>Image</code> object
     */
    public static Image createTriangle(int width, int height, Color color) {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g = image.createGraphics();

        g.setColor(color);

        g.setRenderingHints(RenderingHintsFactory.createBest());

        Polygon polygon = new Polygon();

        polygon.addPoint(width / 2, 0);
        polygon.addPoint(0, height);
        polygon.addPoint(width, height);

        g.fill(polygon);

        g.dispose();

        return image;
    }
}